/**
 * 全局变量
 */
var selectUserId = '';
$(function(){
    /*
    * 加载列表数据
    * */
    $('#listGrid').datagrid({
        url:ROOT_PATH+'/risk/region/queryListByParam.shtml',
        queryParams:{
            sort:'addTime',
            order:'desc'
        },
        idField:'id',
        fitColumns:true,
        pagination:true,
        rownumbers:true,
        singleSelect:true,
        sortOrder:true,
        striped:true,
        fit:true,
        columns:[[
            {field:'id',width:10,checkbox:true},
            {field:'name',title:'风险区域名称',width:10},
            {field:'shortName',title:'风险区域简称',width:10},
            {field:'typeName',title:'风险区域类别',width:10},
            {field:'deptName',title:'风险区域所在部门',width:10},
            {field:'pointNum',title:'风险点个数',width:10},
            {field:'sort',title:'排序',width:10},
            {field:'addUserName',title:'登记人员',width:10},
            {field:'addDeptName',title:'登记部门',width:10},
            {field:'addTime',title:'登记时间',width:10},
            {field:'remarks',title:'备注',width:10}
        ]],
        toolbar: '#toolbar'
    });
    /**
     * 加载下拉列表信息
     *
     */
    //绑定按钮事件
    $("#btn_risk_region_add").on("click",function(){
        addRegion();
    });
    $("#btn_risk_region_edit").on("click",function(){
        editRegion();
    });
    $("#btn_risk_region_delete").on("click",function(){
        deleteRegion();
    });
    //查询按钮绑定事件
    $("#btn_search").on('click',function(){
        searchFun();
    });
    $('#btn_clear').on('click',function(){
        $('#searchForm1').form('clear');
       // $('#searchForm2').form('clear');
    });

});

/**
 * 打开风险区域新增页面
 */
function addRegion(){
    WindowManager.openLayer({
        type: 2,
        title: '新增风险区域信息',
        area: ['800px', '50%'],
        content: ROOT_PATH + '/risk/region/add.shtml',
        /*end:function(){
         $('#listGrid').datagrid("reload");
         }*/
        callBack:function(data){//窗口关闭后的回调函数
            $('#listGrid').datagrid("reload");
            //alert(data);
        }
    });

    /*var index = top.layer.open({
                type: 2,
                title: '新增风险区域信息',
                area: ['800px', '50%'],
                content: ROOT_PATH + '/risk/region/add.shtml',
                end:function(){
                    $('#listGrid').datagrid("reload");
                }
            });*/
}
/**
 * 打开风险可能性等级编辑页面
 */
function editRegion(){
    var selectedRow =  $('#listGrid').datagrid('getSelected');
    if(selectedRow){
        var businessId = selectedRow.id;
        WindowManager.openLayer({
            type: 2,
            title: '编辑风险区域信息',
            area: ['800px', '50%'],
            content: ROOT_PATH + '/risk/region/edit.shtml?businessId='+businessId,
            callBack:function(data){//窗口关闭后的回调函数
                $('#listGrid').datagrid("reload");
                //alert(data);
            }
        });
        /*var index = top.layer.open({
            type: 2,
            title: '编辑风险区域信息',
            area: ['800px', '50%'],
            content: ROOT_PATH + '/risk/region/edit.shtml?businessId='+businessId,
            end:function(){
                $('#listGrid').datagrid("reload");
            }
        });*/
    }else{
        layer.alert("请选择数据！");
    }

}
/**
 * 删除风险等级信息
 */
function deleteRegion(){
    var selectedRow =  $('#listGrid').datagrid('getSelected');
    if(selectedRow) {
        var businessId = selectedRow.id;
        var index = layer.confirm("确定删除改行数据吗？",{btn:["确定","取消"]},function(){
            $.ajax({
                type:'post',
                url:ROOT_PATH + '/risk/region/deleteRegionInfo.shtml?businessId='+businessId,
                dataType:"json",
                success:function(result){
                    if (result.success){
                        layer.msg(result.message,{time:1000,icon:1},function(){
                            $('#listGrid').datagrid('reload');
                        });
                    }else{
                        layer.msg(result.message,{time:1000,icon:1},function(){
                        });
                    }
                }
            });
        })
    }else{
        layer.alert("请选择数据！");
    }
}
/**
 * 查询按钮方法
 */
function searchFun(){
    var search =$('#searchForm1').serializeJson();
    //var search2 =$('#searchForm2').serializeJson();
    //var search = $.extend(search1,search2);
    //排序参数
    search.sort = "addTime";
    search.order='desc';
    $('#listGrid').datagrid('load',search);
}